package com.cw.jeeyt.service.converter.mdata;

import java.util.List;
import java.util.ArrayList;

import com.cw.jeeyt.service.bo.mdata.MdataAreaBo;
import com.cw.jeeyt.dao.model.mdata.MdataAreaDo;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 地区转换类
 *
 * @author admin
 * @date 2021-03-26 22:30:39
 */
public class MdataAreaConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static MdataAreaBo do2Bo(MdataAreaDo model) {
        MdataAreaBo bo = new MdataAreaBo();
        if (model == null) {
            return bo;
        }
        bo.setAreaCode(model.getAreaCode());
        bo.setAreaId(model.getAreaId());
        bo.setAreaName(model.getAreaName());
        bo.setCityCode(model.getCityCode());
        bo.setCityId(model.getCityId());
        bo.setCityName(model.getCityName());
        bo.setCreateTime(model.getCreateTime());
        bo.setProvinceCode(model.getProvinceCode());
        bo.setProvinceName(model.getProvinceName());
        bo.setUpdateTime(model.getUpdateTime());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static MdataAreaDo bo2Do(MdataAreaBo bo) {
        MdataAreaDo model = new MdataAreaDo();
        if (bo == null) {
            return model;
        }
        model.setAreaCode(bo.getAreaCode());
        model.setAreaId(bo.getAreaId());
        model.setAreaName(bo.getAreaName());
        model.setCityCode(bo.getCityCode());
        model.setCityId(bo.getCityId());
        model.setCityName(bo.getCityName());
        model.setCreateTime(bo.getCreateTime());
        model.setProvinceCode(bo.getProvinceCode());
        model.setProvinceName(bo.getProvinceName());
        model.setUpdateTime(bo.getUpdateTime());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<MdataAreaBo> doList2BoList(List<MdataAreaDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), MdataAreaConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<MdataAreaDo> boList2DoList(List<MdataAreaBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), MdataAreaConverter::bo2Do));
    }
}